import sys
import math

def pk(n,v,s):
    nr = 0
    dr = 0
    for i in range(0,n):
        if s[i] == 1:
            nr += 1
        dr += 1
    r = float(nr)/float(dr)
    #print nr,"/",dr
    return r

def avg_precision(v,s):
    n = len(v)
    result = 0
    clicked = 0
    for i in range(0,n):
        if s[i] == 1:
            clicked += 1

    if clicked == 0:
        return result
        
    for i in range(0,min(n,3)):
        if s[i] == 1:
            result += pk(i+1,v,s)

    #print clicked
    result = float(result)/float(clicked)

    return result
        

if __name__ == "__main__":
    f = open(sys.argv[1])
    r_predicted = 0
    r_actual = 0
    c = 0
    for line in f:
        line = line.strip()
        #print line
        parts = line.split()
        v = []
        s = []
        for x in parts[1:]:
            x = x.split(":")
            v.append(int(x[0]))
            s.append(int(x[1]))
        vv_predicted = avg_precision(s,s)
        r_predicted += vv_predicted
        vv_actual = avg_precision(v,v)
        r_actual += vv_actual
        c += 1
        #print r,vv,c
    rr_actual = float(r_actual) / float(c)
    rr_predicted = float(r_predicted) / float(c)
    
    print "Actual:" , rr_actual , r_actual
    print "Predicted:", rr_predicted, r_predicted
    print "Error:", rr_actual - rr_predicted
    print "% Accuracy:", 100 - (100 * float(abs(rr_actual - rr_predicted)) / float(rr_actual)) , "%"
    f.close()
